package net.wwang.blog.commons.global;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @Description: 响应结果通用工具类
 * @Author: WangWei
 */
@NoArgsConstructor
@Data
public class ResponseResult implements Serializable {
    private static final long serialVersionUID = 7703895229185578000L;
    private boolean success;
    private int code;
    private String message;
    private Object data;

    /*构造ResponseState*/
    public ResponseResult(ResponseState responseState){
        this.success = responseState.isSuccess();
        this.code = responseState.getCode();
        this.message = responseState.getMessage();
    }

    /*构造成功失败响应*/
    public static ResponseResult SUCCESS(){
        return new ResponseResult(ResponseState.SUCCESS);
    }
    public static ResponseResult SUCCESS(String message){
        ResponseResult result = new ResponseResult(ResponseState.SUCCESS);
        result.setMessage(message);
        return result ;
    }

    public static ResponseResult UN_AUTHORIZED()
    {
        return new ResponseResult(ResponseState.UN_AUTHORIZED);
    }

    public static ResponseResult UN_AUTHORIZED(String message){
        ResponseResult result = new ResponseResult(ResponseState.UN_AUTHORIZED);
        result.setMessage(message);
        return result ;
    }
    public static ResponseResult FAILED(){
        return new ResponseResult(ResponseState.FAILED);
    }
    public static ResponseResult FAILED(String message){
        ResponseResult result = new ResponseResult(ResponseState.FAILED);
        result.setMessage(message);
        return result ;
    }

    //异常返回
    public static ResponseResult ERROR_404(){
        return new ResponseResult(ResponseState.ERROR_404);
    }
    public static ResponseResult ERROR_403(){
        return new ResponseResult(ResponseState.ERROR_403);
    }
    public static ResponseResult ERROR_405(){
        return new ResponseResult(ResponseState.ERROR_405);
    }

    public static ResponseResult ERROR_504(){
        return new ResponseResult(ResponseState.ERROR_504);
    }

    public static ResponseResult ERROR_505(){
        return new ResponseResult(ResponseState.ERROR_505);
    }

    public static ResponseResult ERROR_500(){
        return new ResponseResult(ResponseState.ERROR_500);
    }

    /*构造数据 */
    public ResponseResult setData(Object data){
        this.data = data;
        return  this;
    }



    /*构造器*/

    public ResponseResult(boolean success, int code, String message) {
        this.success = success;
        this.code = code;
        this.message = message;
    }

    public ResponseResult(boolean success, int code, String message, Object data) {
        this.success = success;
        this.code = code;
        this.message = message;
        this.data = data;
    }

}
